<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            list-style: none;
            margin: 0;
            padding: 0;
        }
        #nav{
            width: 200px;
            border: 1px solid #999;
            box-shadow: 3px 3px 3px #ccc;
            position: absolute;
            top:0px;
            left:0px;
            background-color: #fff;
            display: none;
        }
        #nav li{
            height: 40px;
            line-height: 40px;
            padding: 0 20px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <h1>JS 自定义菜单</h1>
    <hr>

    <ul id="nav">
        <li>复制</li>
        <li>粘贴</li>
        <li>剪切</li>
        <li>刷新</li>
        <li>用迅雷下载</li>
        <li>属性</li>
    </ul>

    <script>
    var nav = document.getElementById('nav');
    // console.log(nav);

    // 出现菜单   获取Event事件
    document.oncontextmenu = function (en) {
        var en = en || window.event;
        // console.log(en);
        var x = en.x;
        var y = en.y;
        // console.log(x,y);
        document.title = x +'|'+y;
        // 改变菜单位置到鼠标附近
        nav.style.left =  x + 'px';
        nav.style.top =  y + 'px';
        nav.style.display = 'block';
        return false;
    }

    // 隐藏菜单
    document.onclick = function () {
        nav.style.display = 'none';
    }

    // 指向变色
    var lis = nav.getElementsByTagName('li');
    // console.log(lis);
    
    for (var i = 0; i < lis.length; i++) {
        lis[i].onmouseover = function() {
            this.style.backgroundColor = '#ccc';
        }
        lis[i].onmouseout = function() {
            this.style.backgroundColor = '#fff';
        }
    }
    </script>
</body>
</html>